//立即函式,函式最外面加上一個小括號,並使用()執行,()在包函式的括號內外皆可
//---------------------------函式宣告
(function IIFE1() {
console.log('立即函式')
}());
(function IIFE2(name) {
console.log('我是'+ name)
})('Tom');
//--------------------------函式運算式
let IIFE3 = (function () {
console.log('立即函式')
})();
let IIFE4 = (function (name) {
console.log('我是'+ name)
}('Tom'));
//--------------------------匿名函式
(function () {
console.log('立即函式')
})();
(function ( name) {
console.log('我是'+ name)
}( name));
let doFirst = function (callback) {
console.log('do first...');
callback(); // <---執行傳入的doLater()
}
/** callback function **/
let doLater = function () {
console.log('do later...')
}
doFirst(doLater);
function a(a){
a();
}
function b(b){
b();
}
function c(c){
console.log('tom')
}
a(b(c))
Ans:tom,a is not a function